using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Prop : BlockBase
{
    int stoneLayer;

    protected override void Awake()
    {
        base.Awake();
        stoneLayer = LayerMask.GetMask("Stone");
    }

    protected override void MoveToRight()
    {
        Ray ray1 = new Ray(transform.position, Vector3.left);
        Ray ray2 = new Ray(transform.position, Vector3.right);
        if (Physics.Raycast(ray2, 100, layer | treeLayer | stoneLayer))
        {
            transform.position = new Vector3(maxXZ - 6, OrigPos.y, OrigPos.z);
        }
        else
        {

            if (Physics.Raycast(ray1, 100, layer | treeLayer | stoneLayer))
            {
                transform.position = new Vector3(maxXZ + 6, OrigPos.y, OrigPos.z);
            }
            else
            {
                transform.position = new Vector3(maxXZ, OrigPos.y, OrigPos.z);
            }

        }
    }

    protected override void MoveToForward()
    {
        Ray ray1 = new Ray(transform.position, Vector3.forward);
        Ray ray2 = new Ray(transform.position, Vector3.back);
        if (Physics.Raycast(ray2, 100, layer | treeLayer | stoneLayer))
        {
            transform.position = new Vector3(OrigPos.x, OrigPos.y, -maxXZ + 6);
        }
        else
        {
            if (Physics.Raycast(ray1, 100, layer | treeLayer | stoneLayer))
            {
                transform.position = new Vector3(OrigPos.x, OrigPos.y, -maxXZ - 6);
            }
            else
            {
                transform.position = new Vector3(OrigPos.x, OrigPos.y, -maxXZ);
            }

        }
    }
}
